package org.springblade.modules.admin.vo.rescue;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPlanContent;
import org.springblade.modules.admin.enums.MaintainPlanContentEnum;
import org.springblade.modules.admin.enums.TaskStatusEnum;
import org.springblade.modules.admin.wrapper.MaintainPlanContentWrapper;

import java.util.Date;

/**
 * 救援列表 model
 *
 * @author zcc
 * @version 1.0
 * @date 2023/2/27 10:21
 */
@Data
public class RescueListVo {

	@ApiModelProperty("任务编号")
	private Long id;

	@ApiModelProperty("电梯id")
	private Long elevatorId;

	@ApiModelProperty("停梯状态： 1-正常 2-停梯")
	private Integer isStop;

	@ApiModelProperty("项目id")
	private Long buildingId;

	@ApiModelProperty("电梯名称")
	private String buildingName;

	@ApiModelProperty("电梯位置")
	private String elevatorAddress;

	@ApiModelProperty("维保员名称+电话")
	private String maintainName;

	@ApiModelProperty("组名称")
	private String groupName;

	@ApiModelProperty("报警人(待救人员)")
	private String rescueName;

	@ApiModelProperty("报警人号码(待救人员)")
	private String rescuePhone;

	@ApiModelProperty("救援类型")
	private Integer rescueType;

	@ApiModelProperty("救援类型名称")
	private String rescueTypeName;

	@ApiModelProperty("救援来源")
	private String rescueSource;

	@ApiModelProperty("救援来源")
	private String rescueSourceName;

	@ApiModelProperty("创建时间")
	private Date createTime;

	@ApiModelProperty("结束时间")
	private Date planEndTime;

	@ApiModelProperty("救援耗时(分钟)")
	private Long useMinute;

	@ApiModelProperty("救援描述")
	private String rescueDesc;

	@ApiModelProperty("实际执行人")
	private String realNames;

	@ApiModelProperty("计划执行人")
	private String personnelRealNames;

	@ApiModelProperty("维修故障原因")
	private String faultReasons;

	@ApiModelProperty("关联的维修id")
	private Long malId;

	@ApiModelProperty("关联的维修状态")
	private Integer malStatus;

	@ApiModelProperty("关联的维修状态名称")
	private String malStatusName;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date malCreateTime;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date malPlanEndTime;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@ApiModelProperty("调度时间")
	private Date allocateTime;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@ApiModelProperty("到达时间")
	private Date arriveTime;

	@ApiModelProperty("到达耗时(分钟)")
	private Long arriveMinute;

	@ApiModelProperty("是否超时到达")
	private Boolean isOvertimeArrival;

	@ApiModelProperty("救援状态")
	private Integer status;

	@ApiModelProperty("救援状态")
	private String statusName;

	@ApiModelProperty("0:未指派，1:已指派")
	private Integer isHasUser = 0;

	@ApiModelProperty("耗时文案时分秒")
	private String wordSecondsDesc;

	@ApiModelProperty(value = "是否转派其它组")
	private Boolean isTransferDept;

	@ApiModelProperty(value = "非电梯部门工单处理人ids")
	private String notEleDeptWorkUsers;

	public void setStatus(Integer status) {
		this.status = status;
		MaintainPlanContent maintainPlanContent = new MaintainPlanContent();
		maintainPlanContent.setTypeStatus(3);
		maintainPlanContent.setStatus(status);
		this.statusName = MaintainPlanContentWrapper.build().entityVO(maintainPlanContent).getStatusName();
	}

	public void setRescueType(Integer rescueType) {
		this.rescueType = rescueType;
		if (rescueType == 1) {
			this.rescueTypeName = "伤人";
		} else if (rescueType == 0) {
			this.rescueTypeName = "困人";
		}
	}

	public void setMaintainName(String maintainName) {
		this.maintainName = maintainName;
		if (StrUtil.isNotEmpty(maintainName)) {
			this.isHasUser = 1;
		} else {
			this.isHasUser = 0;
		}
	}

	public void setMalStatus(Integer malStatus) {
		this.malStatus = malStatus;
		if (malStatus != null) {
			this.malStatusName = TaskStatusEnum.getTaskName(MaintainPlanContentEnum.MAINTAIN_WX.getId(), malStatus);
		}
	}

	public Long getArriveMinute() {
		if (this.createTime != null && this.arriveTime != null) {
			return DateUtil.between(this.arriveTime, this.createTime, DateUnit.MINUTE);
		}

		return null;
	}

	public void setNotEleDeptWorkUsers(String notEleDeptWorkUsers) {
		this.notEleDeptWorkUsers = notEleDeptWorkUsers;
		if (Func.isNotBlank(notEleDeptWorkUsers)) {
			this.isTransferDept = Boolean.TRUE;
		}
	}
}
